<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品广告列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>名称：</p>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <p>发布状态：</p>
                                <select name="status" th:with="type=${@dict.getType('common_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="kkad:goodsad:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="kkad:goodsad:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('kkad:goodsad:edit')}]];
        var removeFlag = [[${@permission.hasPermi('kkad:goodsad:remove')}]];
        var statusDatas = [[${@dict.getType('common_status')}]];
        var prefix = ctx + "kkad/goodsad";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "id",
     		    sortOrder: "desc",
                modalName: "商品广告",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'null',
                    visible: false
                },
                {
                    field : 'img',
                    title : '图标',
                    formatter: function(value, row, index) {
                       if(value){
                           return `<img src='${value}' width=150 height=200 />`
                       }
                    }
                },
                {
                    field : 'name', 
                    title : '名称',
                    formatter: function(value, row, index) {
                		return $.table.tooltip(value);
                	}
                },
                {
                    field : 'provider',
                    title : '供应商'
                },
                {
                    field : 'link', 
                    title : '链接',
                    formatter: function(value, row, index) {
                		return $.table.tooltip(value);
                	}
                },
                {
                    field : 'status', 
                    title : '发布状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field : 'weight', 
                    title : '权重'
                },
                {
                    field : 'tags', 
                    title : '关联标签'
                },
                {
                    field : 'showTags',
                    title : '展示标签'
                },
                {
                    field : 'topTag',
                    title : '左上角标签'
                },
                {
                    field : 'createdTime', 
                    title : '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.status == 1){
                          actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\', 0)"><i class="fa fa-remove"></i>下线</a> ');
                          actions.push('<a class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="preview(\'' + row.id + '\', 0)"><i class="fa fa-remove"></i>预览</a>');
                        }
                        if(row.status == 0){
                          actions.push('<a class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\', 1)"><i class="fa fa-remove"></i>上线</a> ');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

         function updateStatus(id, status){
		   	let msg = status==1?'确定要上线吗?': '确定要取下线吗?';
		    $.modal.confirm(msg, function() {
				$.operate.post(prefix + "/updateStatus/" + id, { "status": status});
		    })
		}

		function preview(id){
		   let url = `${prefix}/preview/${id}`
		   $.modal.openFull("广告预览", url);
		}

    </script>
</body>
</html>